package com.sob.bountyhunter;

import java.util.Random;

import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Circle;
import org.newdawn.slick.geom.Rectangle;

public class IluminacionMapa {
	private int width, height;
	private Image img;
	
	public IluminacionMapa(int w, int h) throws SlickException{
		width=w;
		height=h;
		img=new Image(width, height);
		img.setAlpha(1f);
	}
	
	public void fillBlack(Graphics graphics){
		try {
			Graphics gTemp=img.getGraphics();
			Graphics.setCurrent(gTemp);
			
			Rectangle r=new Rectangle(0, 0, width, height);
			gTemp.setColor(Color.black);
			gTemp.fill(r);
			
			//gTemp.setColor(Color.red);
			//gTemp.drawRect(0, 0, width, height);
			
			Graphics.setCurrent(graphics);
		} catch (SlickException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void clearCircle(Graphics graphics, float x, float y, float r){
		try {
			Graphics gTemp;
			gTemp = img.getGraphics();
			Graphics.setCurrent(gTemp);

			int maxAlpha=250;
			float paso=maxAlpha/r;
			Random rand=new Random();
			float pow=1; //rand.nextFloat();
			
			for(float i=r;i>=0;i--){				
				float val=maxAlpha-(i*paso);
				gTemp.setColor(new Color(1f , 1f, 1f,val/1000));
				Circle c=new Circle(x, y, i);
				//gTemp.fill(c);
				gTemp.fill(c);
			}

			Graphics.setCurrent(graphics);
		} catch (SlickException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	
	public void render(GameContainer gameContainer, Graphics graphics, float x, float y)
	{
		fillBlack(graphics);
		clearCircle(graphics, 100, 100, 50);
		clearCircle(graphics, 200, 100, 50);
		graphics.setDrawMode(Graphics.MODE_COLOR_MULTIPLY);
		img.draw(x,y);
		graphics.setDrawMode(Graphics.MODE_NORMAL);
	}
}
